package com.thy.axq.action;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.thy.axq.util.PropertiesUtil;

/*
 * git测试提交
 * dev20170623
 * 本地下载更新dev20170623
 */
public  class ActiveMqConnClient {
	
	static Log logger=LogFactory.getLog(ActiveMqConnClient.class);
	static String activeMq="system";
	private static ActiveMQConnectionFactory actualConnectionFactory = new ActiveMQConnectionFactory();
	private static PooledConnectionFactory connectionFactory = new PooledConnectionFactory();
	static {
		actualConnectionFactory.setUserName(PropertiesUtil.getString(activeMq, "ACTIVEMQ_USERNAME"));
		actualConnectionFactory.setPassword(PropertiesUtil.getString(activeMq,"ACTIVEMQ_PASSWORD"));
		actualConnectionFactory.setBrokerURL(PropertiesUtil.getString(activeMq,"ACTIVEMQ_QUEUE_URL"));
		connectionFactory.setConnectionFactory(actualConnectionFactory);
		// 初始化链接
		connectionFactory.setCreateConnectionOnStartup(true);
		// 线程池最大连接数设置
		try {
			//connectionFactory.setMaxConnections(PropertiesUtil.getInt(activeMq,"ACTIVEMQ_MAX_CONNECTIONS"));
		} catch (Exception e) {
			//logger.error(" 线程池最大连接数设置发生异常： 异常信息如下：",e);
		}
       //设置每个连接使用的最大活动会话数
		try {
			connectionFactory.setMaximumActiveSessionPerConnection(PropertiesUtil.getInt(activeMq,"ACTIVEMQ_SESSION_CONNECTIONS"));
		} catch (Exception e) {
			logger.error("设置每个连接使用的最大活动会话数发生异常异常信息如下：",e);
		}
		//后台对象清理时，休眠时间超过了30000毫秒的对象为过期  
		connectionFactory.setTimeBetweenExpirationCheckMillis(30000); 
		
	}
	
	   public static PooledConnectionFactory getActiveMQConnectionFactory() {
			return connectionFactory;
		}
	   
       public static void main(String[] args){
	      getActiveMQConnectionFactory();
	      System.out.println(PropertiesUtil.getString(activeMq, "ACTIVEMQ_USERNAME"));
	      System.out.println("---------------");
   }
}
